package com.college_career_system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.college_career_system.dao.RecruitMapper;
import com.college_career_system.dao.UserMapper;
import com.college_career_system.pojo.po.SubmitRecruit;
import com.college_career_system.dao.SubmitRecruitMapper;
import com.college_career_system.service.SubmitRecruitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college_career_system.utils.ResponseCode;
import com.college_career_system.utils.ResponseResult;
import com.college_career_system.utils.StringUtil;
import com.college_career_system.utils.TokenUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Empty
 * @since 2022-12-04
 */
@Service
public class SubmitRecruitServiceImpl extends ServiceImpl<SubmitRecruitMapper, SubmitRecruit> implements SubmitRecruitService {

    private final SubmitRecruitMapper submitRecruitMapper;
    private final UserMapper userMapper;
    private final RecruitMapper RecruitMapper;

    public SubmitRecruitServiceImpl(SubmitRecruitMapper submitRecruitMapper, UserMapper userMapper, com.college_career_system.dao.RecruitMapper recruitMapper) {
        this.submitRecruitMapper = submitRecruitMapper;

        this.userMapper = userMapper;

        RecruitMapper = recruitMapper;
    }

    @Override
    @Transactional
    public JSONObject addSubmitRecruit(HttpServletRequest request, Integer recruitId, String enterpriseId) {

        // TODO 方法没写
        if(StringUtil.isEmptyOrNull(enterpriseId)) {
            return ResponseResult.failure("信息填写不完善！", ResponseCode.STATUS_ERROR);
        }
        SubmitRecruit submitRecruit = new SubmitRecruit();
        submitRecruit.setRecruitId(recruitId).setEnterpriseId(Long.valueOf(enterpriseId))
                .setUid(TokenUtil.getId(request)).
                setSubmitTime(LocalDateTime.now());
        submitRecruitMapper.insert(submitRecruit);
        return ResponseResult.success();
    }
}
